home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 September / CHIP Eylül 1998.iso / Slackwar / docs / mini / VPN < prev    next >
Text File  |  1998-01-15  |  16KB  |  461 lines

  1.   The VPN HOWTO
  2.   Arpad Magosanyi <mag@bunuel.tii.matav.hu> v0.2,7 Aug1997
  3.  
  4.   1.  Changes
  5.  
  6.   The 'no controlling tty problem' -> -o 'BatchMode yes' by Zot O'Connor
  7.   <zot@crl.com>
  8.  
  9.   warning about kernel 2.0.30 by mag
  10.  
  11.   2.  Blurb
  12.  
  13.   This is the Linux VPN howto, a collection of information on how to set
  14.   up a Virtual Protected Network in Linux (and other unices in general).
  15.  
  16.   2.1.  Copyright
  17.  
  18.   This document is part of the Linux HOWTO project. The copyright notice
  19.   is the following: Unless otherwise stated, Linux HOWTO documents are
  20.   copyrighted by their respective authors. Linux HOWTO documents may be
  21.   reproduced and distributed in whole or in part, in any medium physical
  22.   or electronic, as long as this copyright notice is retained on all
  23.   copies. Commercial redistribution is allowed and encouraged; however,
  24.   the author would like to be notified of any such distributions. All
  25.   translations, derivative works, or aggregate works incorporating any
  26.   Linux HOWTO documents must be covered under this copyright notice.
  27.   That is, you may not produce a derivative work from a HOWTO and impose
  28.   additional restrictions on its distribution. Exceptions to these rules
  29.   may be granted under certain conditions; please contact the Linux
  30.   HOWTO coordinator at the address given below. In short, we wish to
  31.   promote dissemination of this information through as many channels as
  32.   possible. However, we do wish to retain copyright on the HOWTO
  33.   documents, and would like to be notified of any plans to redistribute
  34.   the HOWTOs. If you have questions, please contact Greg Hankins, the
  35.   Linux HOWTO coordinator, at gregh@sunsite.unc.edu via email.
  36.  
  37.   2.2.  Disclaimer
  38.  
  39.   As usual: the author not responsible for any damage. For the correct
  40.   wording, see the relevant part of the GNU GPL 0.1.1
  41.  
  42.   2.3.  Disclaimer
  43.  
  44.   We are dealing with security: you are not safe if you haven't got good
  45.   security policy, and other rather boring things.
  46.  
  47.   2.4.  Credits
  48.  
  49.   Thanks to all of who has written the tools used.
  50.  
  51.   Thanks to Zot O'Connor <zot@crl.com> for pointing out the "no
  52.   controlling tty" problem, and it's solution.
  53.  
  54.   2.5.  State of this document
  55.  
  56.   This is very preliminary. You should have thorough knowledge of
  57.   administrating IP, at least some knowledge of firewalls, ppp and ssh.
  58.   You should know them anyway if you want to set up a VPN. I just
  59.   decided to write down my experiences not to forget them. There are
  60.   possibly some security holes indeed. To be fair I've tried it on hosts
  61.   configured as routers not firewalls, saying: It's simple from that
  62.   point.
  63.  
  64.   2.6.  Related documentations
  65.  
  66.   ╖  The Linux Firewall-HOWTO /usr/doc/HOWTO/Firewall-HOWTO
  67.  
  68.   ╖  The Linux PPP-HOWTO /usr/doc/HOWTO/PPP-HOWTO.gz
  69.  
  70.   ╖  The ssh documentations /usr/doc/ssh/*
  71.  
  72.   ╖  The Linux Network Admins' Guide
  73.  
  74.   ╖  NIST Computer Security Special Publications
  75.      http://csrc.ncsl.nist.gov/nistpubs/
  76.  
  77.   ╖  Firewall list (majordomo@greatcircle.com)
  78.  
  79.   3.  Introduction
  80.  
  81.   As firewalls are in more and more widely use in internet and intranet
  82.   security, the ability to do nice VPNs is important. Here are my
  83.   experiences. Comments are welcome.
  84.  
  85.   3.1.  Naming conventions
  86.  
  87.   I will use the terms "master firewall" and "slave firewall", though
  88.   making a VPN has nothing to do with client-server architecture. I
  89.   simply refer to them as the active and passive participants of the
  90.   connection's setup. The host which is starts the setup will be
  91.   referred as the master, and the passive participant will be the slave.
  92.  
  93.   4.  Doing it
  94.  
  95.   4.1.  Planning
  96.  
  97.   Before you start to set up your system, you should know the networking
  98.   details. I assume you have two firewalls protecting one intranet per
  99.   firewall, and they are both connected to the internet. So now you
  100.   should have two network interfaces (at least) per firewall. Take a
  101.   sheet of paper, write down their IP addresses and network mask. You
  102.   will need one more IP adresses per firewall for the VPN you want to do
  103.   now. Those addresses should be outside of your existing subnets. I
  104.   suggest using addresses from the "private" address ranges. They are
  105.   the followings:
  106.  
  107.   ╖  10.0.0.0 - 10.255.255.255
  108.  
  109.   ╖  172.16.0.0 - 172.31.255.255
  110.  
  111.   ╖  192.168.0.0 - 192.168.255.255
  112.  
  113.   For the sake of example, here's a sample configuration: The two
  114.   bastions are called fellini and polanski. They have one interface for
  115.   the internet (-out), one for the intranet (-in), and one for the vpn
  116.   (-vpn). The addresses and netmasks:
  117.  
  118.   ╖  fellini-out: 193.6.34.12 255.255.255.0
  119.  
  120.   ╖  fellini-in: 193.6.35.12 255.255.255.0
  121.  
  122.   ╖  fellini-vpn: 192.168.0.1 point-to-point
  123.  
  124.   ╖  polanski-out: 193.6.36.12 255.255.255.0
  125.  
  126.   ╖  polanski-in: 193.6.37.12 255.255.255.0
  127.  
  128.   ╖  polanski-vpn: 192.168.0.2 point-to-point
  129.  
  130.   So we have the plan.
  131.  
  132.   4.2.  Gathering the tools
  133.  
  134.   You will need a
  135.  
  136.   ╖  Linux firewall
  137.  
  138.   ╖  kernel
  139.  
  140.   ╖  very minimal configuration
  141.  
  142.   ╖  ipfwadm
  143.  
  144.   ╖  fwtk
  145.  
  146.   ╖  Tools for the VPN
  147.  
  148.   ╖  ssh
  149.  
  150.   ╖  pppd
  151.  
  152.   ╖  sudo
  153.  
  154.   ╖  pty-redir
  155.  
  156.   Current versions:
  157.  
  158.   ╖  kernel: 2.0.29 Use a stable kernel, and it must be newer than
  159.      2.0.20, because the ping'o'death bug. At the time of writing 2.0.30
  160.      is the last "stable" kernel, but it has some bugs. If you want to
  161.      have the fast and cool networking code introduced in it, try a
  162.      prepatch. the 3rd is working for me nicely.
  163.  
  164.   ╖  base system: I prefer Debian. YMMV. You absolutely don't want to
  165.      use any big packages, and you never even tought of using sendmail,
  166.      of course. You also definitely don't want to enable telnet, ftp,
  167.      and the 'r' commands (as usual in case of any other unix hosts).
  168.  
  169.   ╖  ipfwadm: I've used 2.3.0
  170.  
  171.   ╖  fwtk: I've used 1.3
  172.  
  173.   ╖  ssh: >= 1.2.20. There are problems with the underlying protocol in
  174.      the older versions.
  175.  
  176.   ╖  pppd: I've used 2.2.0f for the tests, but I'm not sure if is it
  177.      secure, this is why I turned the setuid bit off, and used sudo to
  178.      launch it.
  179.  
  180.   ╖  sudo: 1.5.2 the newest I am aware of
  181.  
  182.   ╖  pty-redir: It is written by me. Try
  183.      ftp://ftp.vein.hu/ssa/contrib/mag/pty-redir-0.1.tar.gz. Its version
  184.      number is 0.1 now. Tell me it there is any problem with it.
  185.   4.3.  Compile and install
  186.  
  187.   Compile or otherwise install the gathered tools. Look at every one's
  188.   documentation (and the firewall-howto) for details. Now we have the
  189.   tools.
  190.  
  191.   4.4.  Configure the other subsystems
  192.  
  193.   Configure your firewall rules, etc. You need to enable ssh traffic
  194.   between the two firewll hosts. It means a connection to port 22 on the
  195.   slave from the master. Start sshd on the slave and verify if you can
  196.   login. This step is untested, please tell me your results.
  197.  
  198.   4.5.  Set up the accounts for the VPN
  199.  
  200.   Create an account on the slave firewall use your favourite tool (e.g.
  201.   vi, mkdir, chown, chmod) you might create an account on the master
  202.   also, but I think you want to set up the connection at boot time, so
  203.   your ordinary root account will do. Can anyone point out risks on
  204.   using the root account on the master?
  205.  
  206.   4.6.  Generate an ssh key for your master account
  207.  
  208.   Use the ssh-keygen program. Set empty password for the private key if
  209.   you want to do automatic setup of the VPN.
  210.  
  211.   4.7.  Set up automatic ssh login for the slave account
  212.  
  213.   Copy the newly generated public key in the slave account under
  214.   .ssh/authorized_keys, and set up file permissions like the following:
  215.  
  216.   drwx------ 2 slave slave 1024 Apr 7 23:49 ./
  217.   drwx------ 4 slave slave 1024 Apr 24 14:05 ../
  218.   -rwx------ 1 slave slave 328 Apr 7 03:04 authorized_keys
  219.   -rw------- 1 slave slave 660 Apr 14 15:23 known_hosts
  220.   -rw------- 1 slave slave 512 Apr 21 10:03 random_seed
  221.  
  222.   The first row being ~slave/.ssh, and the second is ~slave.
  223.  
  224.   4.8.  Tighten ssh security on the bastions.
  225.  
  226.   It means the followings on my setup in sshd_conf:
  227.  
  228.   PermitRootLogin no
  229.   IgnoreRhosts yes
  230.   StrictModes yes
  231.   QuietMode no
  232.   FascistLogging yes
  233.   KeepAlive yes
  234.   RhostsAuthentication no
  235.   RhostsRSAAuthentication no
  236.   RSAAuthentication yes
  237.   PasswordAuthentication no
  238.   PermitEmptyPasswords no
  239.  
  240.   Password authentication is turned off, so login is only possible with
  241.   authorized keys. (You've turned off telnet and the 'r' commands of
  242.   course).
  243.  
  244.   4.9.  Enable execution of ppp and route for both accounts.
  245.  
  246.   As the master account is the root in my case, it has nothing to do.
  247.   For the slave account, the following lines appear in /etc/sudoers:
  248.  
  249.   Cmnd_Alias VPN=/usr/sbin/pppd,/usr/local/vpn/route
  250.   slave ALL=NOPASSWD: VPN
  251.  
  252.   As you can see, I am using some scripts to set up ppp and the routing
  253.   tables on the slave host.
  254.  
  255.   4.10.  Do the scripting
  256.  
  257.   On the master host there is a full-blown init script I am using:
  258.  
  259.   #! /bin/sh
  260.   # skeleton      example file to build /etc/init.d/ scripts.
  261.   #               This file should be used to construct scripts for /etc/init.d.
  262.   #
  263.   #               Written by Miquel van Smoorenburg <miquels@cistron.nl>.
  264.   #               Modified for Debian GNU/Linux
  265.   #               by Ian Murdock <imurdock@gnu.ai.mit.edu>.
  266.   #
  267.   # Version:      @(#)skeleton  1.6  11-Nov-1996  miquels@cistron.nl
  268.   #
  269.  
  270.   PATH=/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/bin/X11/:
  271.   PPPAPP=/home/slave/ppp
  272.   ROUTEAPP=/home/slave/route
  273.   PPPD=/usr/sbin/pppd
  274.   NAME=VPN
  275.   REDIR=/usr/local/bin/pty-redir
  276.   SSH=/usr/bin/ssh
  277.   MYPPPIP=192.168.0.1
  278.   TARGETIP=192.168.0.2
  279.   TARGETNET=193.6.37.0
  280.   MYNET=193.6.35.0
  281.   SLAVEWALL=polanski-out
  282.   SLAVEACC=slave
  283.  
  284.   test -f $PPPD || exit 0
  285.  
  286.   set -e
  287.  
  288.   case "$1" in
  289.     start)
  290.           echo setting up vpn
  291.           $REDIR $SSH -o 'Batchmode yes' -t -l $SLAVEACC $SLAVEWALL sudo $PPPAPP >/tmp/device
  292.           TTYNAME=`cat /tmp/device`
  293.   echo tty is $TTYNAME
  294.           sleep 10s
  295.           if [ ! -z $TTYNAME ]
  296.           then
  297.           $PPPD $TTYNAME ${MYPPPIP}:${TARGETIP}
  298.           else
  299.                   echo FAILED!
  300.                   logger "vpn setup failed"
  301.           fi
  302.           sleep 5s
  303.           route add -net $TARGETNET gw $TARGETIP
  304.           $SSH -o 'Batchmode yes' -l $SLAVEACC $SLAVEWALL sudo $ROUTEAPP
  305.       ;;
  306.     stop)
  307.           ps -ax | grep "ssh -t -l $SLAVEACC " | grep -v grep | awk '{print $1}' | xargs kill
  308.       ;;
  309.     *)
  310.       # echo "Usage: /etc/init.d/$NAME {start|stop|reload}"
  311.       echo "Usage: /etc/init.d/$NAME {start|stop}"
  312.       exit 1
  313.       ;;
  314.   esac
  315.  
  316.   exit 0
  317.  
  318.   The slave uses one script for routing setup (/usr/local/vpn/route):
  319.  
  320.   #!/bin/bash
  321.   /sbin/route add -net 193.6.35.0 gw 192.168.0.1
  322.  
  323.   and its .ppprc consists of the following:
  324.  
  325.   passive
  326.  
  327.   5.  Look at what's happening:
  328.  
  329.   The master logs in into the slave, starts pppd, and redirects this all
  330.   thing into a local pty. It consists of the following steps:
  331.  
  332.   ╖  allocating a new pty
  333.  
  334.   ╖  sshing into the slave
  335.  
  336.   ╖  running pppd on the slave
  337.  
  338.   ╖  the master runs pppd in this local pty
  339.  
  340.   ╖  and sets up the routing table on the client.
  341.  
  342.   There are (not very tight) timing considerations involved, this is why
  343.   that 'sleep 10s'.
  344.  
  345.   6.  Doing it by hand.
  346.  
  347.   6.1.  Logging in
  348.  
  349.   You've already tried if ssh works well, aren't you? If the slave
  350.   refuses to log you in, read the logs. Perhaps there are problems with
  351.   file permissions or the sshd setup.
  352.  
  353.   6.2.  Firing up ppp
  354.  
  355.   Log in into slave, and issue:
  356.  
  357.   sudo /usr/sbin/pppd passive
  358.  
  359.   You should see garbage coming at this point. If it works good, if not,
  360.   there is some problem either with sudo, either with pppd. Look what
  361.   the commands had said, and at the logs and at the /etc/ppp/options,
  362.   and the .ppprc file.  If it works, write this 'passive' word into
  363.   .ppprc, and try again. To get rid off the garbage and continue
  364.   working, press enter,'~' and '^Z'.  You should have the master's
  365.   prompt now, and kill %1. See the section about tuning if you want to
  366.   know more of the escape character.
  367.  
  368.   6.3.  Together the two
  369.  
  370.   Well, then
  371.  
  372.   ssh -l slave polanski sudo /usr/sbin/pppd
  373.  
  374.   should work also, and deliver the garbage right into your face.
  375.  
  376.   6.4.  Pty redirecting
  377.  
  378.   Try to redirect this whole thing this time:
  379.  
  380.   /usr/local/bin/pty-redir /usr/bin/ssh -l slave polanski sudo /usr/sbin/pppd
  381.  
  382.   Nice long sentence isn't it?  You should use the full path into the
  383.   ssh executable, as the pty-redir program allows only this form for
  384.   security reasons.  Now you've got a device name from the program.
  385.   Let's say, you've got /dev/ttyp0  You can use the ps command to look
  386.   what has happened. Look for 'p0'
  387.  
  388.   6.5.  Is anything on the device?
  389.  
  390.   Try
  391.  
  392.   /usr/sbin/pppd /dev/ttyp0 local 192.168.0.1:192.168.0.2
  393.  
  394.   to establish the connection. Look at the output of the ifconfig
  395.   command to see if the device has established, and use ping to check
  396.   your virtual net.
  397.  
  398.   6.6.  Setting up the routes
  399.  
  400.   Set up the routes on the master host, and on the slave also. Now you
  401.   should be able to ping one host in one intranet from other host in the
  402.   other intranet.  Set up the additional firewalling rules. Now as you
  403.   have the VPN, you can set up the rules concerning the connectivity of
  404.   the two intranets.
  405.  
  406.   7.  Tuning
  407.  
  408.   7.1.  Configuration tuning
  409.  
  410.   As I said this HOWTO is mainly a quick memo on how I had set up a VPN.
  411.   There are things in the configuration I didn't experiment yet. These
  412.   things will go into their place when I try them, or anyone tells me
  413.   "it works in the following way" The most important thing is that the
  414.   connection ppp uses is not 8-bit yet. I believe it has something to do
  415.   either with ssh configuration or the pty setup. In this configuration
  416.   ssh uses the tilde (~) character as an escape character. It might stop
  417.   or slow down the communication, as any newline-tilde sequence causes
  418.   ssh to give a prompt. Ssh documentation said:  <On most systems,
  419.   setting the escape character to ``none'' will also make the session
  420.   transparent even if a tty is used.> The corresponding flag to ssh is
  421.   '-e', and you can also set it in the configuration file.
  422.  
  423.   7.2.  Bandwith vs. cicles
  424.  
  425.   Creating anything virtual comes with utilization of real-world
  426.   resources. A VPN eats up bandwidth and computing resources. The goal
  427.   would be to get balance between the two. You can tune it with the '-C'
  428.   switch or the 'CompressionLevel' option. You might try using another
  429.   cipher, but I don't recommend it. Also note that the round-trip-time
  430.   can be longer if you use better compression. Any experiments on it are
  431.   welcome.
  432.  
  433.   8.  Vulnerability analisis
  434.  
  435.   I try to cover here the vulnerability issues arising from this
  436.   particular setup and VPNs in general. Any comments are warmly welcome.
  437.  
  438.   ╖  sudo: Well, I'm excessively using sudo. I believe it's still safer
  439.      than using setuid bits. It's still a backdraw of Linux that it
  440.      hasn't got more fine-grained access control. Waiting for POSIX.6
  441.      compatibility <http://www.xarius.demon.co.uk/software/posix6/>.
  442.      What is worse, there are shell scripts which are getting called
  443.      through sudo. Bad enough. Any idea out there?
  444.  
  445.   ╖  pppd: It runs suid root also. It can be configured by user's
  446.      .ppprc. There might be some nice buffer overruns in it. The bottom
  447.      line: secure your slave account as tightly as you can.
  448.  
  449.   ╖  ssh: Beware that ssh older than 1.2.20 has security holes. What is
  450.      worse, we made a configuration such when the master account had
  451.      been compromised, the slave account is also compromised, and wide
  452.      open to attacks using the two sudoed programs. It is because I've
  453.      choosen not to have password on the master's secret key to enable
  454.      automatic setup of the VPN.
  455.  
  456.   ╖  firewall: With inproperly set firewall rules on one bastion, you
  457.      open both of the intranets. I recommend using IP masquerading (as
  458.      setting up incorrect routes is a bit less trivial), and doing hard
  459.      control on the VPN interfaces.
  460.  
  461.